package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;

public class FileInputStreamDemo {
    public static void main(String[] args) {
        String p = FileDemo.getJavaFilePath(FileInputStreamDemo.class, "") + "/1.txt";
        System.out.println(read(new byte[4],p));
    }
    public static String read(byte b[],String filePath){
        String s  = new String();
        int n=0;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(filePath);
            while((n =fis.read(b))!=-1){
                System.out.println(n+"--");
                s += new String(b,0,n,"gbk");

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            System.out.println(new String(s.getBytes("gbk"),"gbk"));
            System.out.println(s.getBytes().length);
            byte[] bt = new byte[20];
            bt = s.getBytes();
            for(int i=0;i<bt.length;i++){
                System.out.printf(bt[i]+" ");
            }
            System.out.println();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        for(int i=0;i<s.length();i++){

        }
        return s;
    }
}
